* Compliance Agreements: 
* Emergent Flexibility in the Inter-American Human Rights System
*   Aníbal Pérez-Liñán
*   Mariana Brocca
*   Isabel Anayanssi Orizaga Inzunza

version 16.1
capture: net install psweight, replace from(http://fmwww.bc.edu/RePEc/bocode/p) 
capture: net install dmout, replace from(http://fmwww.bc.edu/RePEc/bocode/d) 
capture: net install st0085_2, replace from(http://www.stata-journal.com/software/sj14-2) 
capture: net install gr0059_1, replace from(http://www.stata-journal.com/software/sj15-1)
capture: net install st0565, replace from(http://www.stata-journal.com/software/sj19-3)
capture: ssc install indeplist, replace
capture: ssc install moss, replace
capture: ssc install matsort, replace
capture: net install csdid, replace from(http://fmwww.bc.edu/RePEc/bocode/c)
capture: ssc install drdid, replace

 use "ndrl_agreements", clear
 
*** Descriptives ***
   ** Table 1. Compliance Agreements Reported by the IACHR
 preserve 
  sort case 
  collapse (max) agreement (last) state agreement_yr victims, by(case) 
     sort agreement_yr
     list state agreement_yr victims  if agreement == 1, noobs noheader clean compress
  * Percentage of cases with agreements
    tab agreement
 restore

 ** Discussion of the dataset
  * Percentage of observations "treated" by compliance agreements
   tab postagree if y_any!=.
  * Types of measures recommended by the Commission 
  preserve 
   sort repcode
   decode rtype_cm, generate(rtype_)
   collapse (max) agreement y_full y_part (last) rtype_, by(repcode)
   * Types of recommendations
    tab rtype_
  restore

 ** For recommendation-years
  * Proportion of treated recommendation-years
    tab postagree
     
*** Analisis ***
 ** 1 ** Propensity Score Matching
 
   use "ndrl_agreements", clear
   
  * Create and label state dummies: cow_1 through cow_22
  tabulate cowcode, generate(cow_)
  foreach var of varlist * {
  local varlabel : var label `var'
  local newname : subinstr local varlabel "cowcode==" "", all
  label variable `var' "`newname'"
  }
  * Create and label reparation type dummies: rty_1 through rty_5
  tabulate rtype_cm, generate(rty_)
  foreach var of varlist * {
  local varlabel : var label `var'
  local newname : subinstr local varlabel "rtype_cm==" "", all
  label variable `var' "`newname'"
  }
  drop rty_1 // referece category

  * Model 3.1. Treatment: IPW 
  psweight ipw postagree rty_*      art51pub c.t##c.t##c.t##c.t cow_*   
  
  ** Table 2: Balance table
  dmout rty_* art51pub t cow_* using balance1                    , by(postagree) list csv replace
  dmout rty_* art51pub t cow_* using balance2 [iweight = _weight], by(postagree) list csv replace
  
  * Estimate effects with and without matching
  reg y_any postagree
  reg y_any postagree [iweight = _weight]
  
  ** Table 3 - IPW and Selection
  * Model 3.1. Treatment: IPW 
  logit            postagree i.rtype_cm art51pub c.t##c.t##c.t##c.t cow_*    // PSW model
   est store M31
  * Model 3.2. Outcome with Inverse Propensity Weight Matching
  mecloglog y_any i.postagree i.rtype_cm art51pub c.t##c.t##c.t##c.t              [iweight = _weight] || case: , startvalues(zero)	 
   est store M32
  * Model 3.3 After 2002	 
  mecloglog y_any i.postagree i.rtype_cm art51pub c.t##c.t##c.t##c.t if period==1 [iweight = _weight] || case: , startvalues(zero)
    est store M33
  * Model 3.4 Unmatched sample	
  mecloglog y_any i.postagree i.rtype_cm art51pub c.t##c.t##c.t##c.t                                  || case: , startvalues(zero)
   est store M34
   
 ** Table 3. Discrete-Time Duration Estimates
  esttab M31 M32 M33 M34  /// 
      using "Table_3.rtf", replace  b(%9.2f) se	///  
	      mtitles("IPW: Treatment" "IPW: Outcome" "IPW (after 2002)" "Unmatched") ///
	  	  starlevels(* 0.05) nobase noomit label nodepvars  order(1.postagree) ///
	      title("Table 3. Discrete-Time Duration Models")  
  
  ** Figure 2. Expected Time to Compliance for Recommendations with and without Agreements
   est restore M33
   margins postagree, post
   coefplot, transform(* = 1/(@b)) noci saving(ETC, replace) recast(dropline)  /// 
     mlabel mlabsize(large) format(%3.0f) msymbol(|) xtitle("Years from art. 50 report to the first form of compliance (partial or full)", size(large))  ///
     ylabel(1 "No agreement" 2 "After agreement" , labsize(large))	xsize(7) ysize(3) xlabel(0(5)15)	  

  ** Table 4. DiD
  * Model 4.1. DiD 
  reg y_any postagree agreement period , cluster(case)
   est store M41
  * Model 4.2. DiD with PSW 
  reg y_any postagree agreement period [iweight = _weight], cluster(case)
   est store M42 
  * Model 4.3. DiD with adjustments  
  reg y_any postagree agreement period rty_* art51pub c.t##c.t##c.t##c.t, cluster(case)
   est store M43
     konfound postagree
  * Model 4.4. DiD with adjustments and PSW
  reg y_any postagree agreement period rty_* art51pub c.t##c.t##c.t##c.t [iweight = _weight], cluster(case)
   est store M44
     konfound postagree
   
  ** Table 4. Discrete-Time Duration Estimates 
  esttab M41 M42 M43 M44 /// 
      using "Table_4.rtf", replace  b(%9.2f) se	///  
	      mtitles("DiD" "DiD with PSW" "DiD with adjustments" "PSW and adjustments") ///
	  	  starlevels(* 0.05) nobase noomit label nodepvars  ///
	      title("Table 4. Difference-in-Differences Models")  		

 ** Table 5. Estimate with heterogeneous period effects
  est restore M41
   global bany1 = _b[postagree]
  csdid y_any , time(year) gvar(agreement_yr) agg(simple) cluster(case)
    global bany1h = _b[ATT]
    * How much does the estimate for DiD change if we allow for heterogeneity?
	di 100*($bany1h-$bany1)/$bany1
  est restore M42	 
    global bany2 = _b[postagree]
  csdid y_any [iweight = _weight], time(year) gvar(agreement_yr) agg(simple) cluster(cowcode)
    global bany2h = _b[ATT]
	* How much does the estimate for DiD change if we allow for heterogeneity?
	di 100*($bany2h-$bany2)/$bany2       
 